import qs from 'qs'
export const ajax = {
    get(url, options) {
        return new Promise(function (resolve, reject) {
            console.log(url);
            var { params } = options || {}
            params = qs.stringify(params)
            url = params ? url + '?' + params : url
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url);
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.send();
            xhr.onreadystatechange = function () {
                if (this.status == 200 && this.readyState == 4) {
                    resolve({ data: JSON.parse(this.responseText) })
                } else {
                    reject(new Error(this.statusText))
                }
            }
        })
    }
}